/**
 * Copyright(c) 2013 Jade Techonologies, Ltd.
 *
 * History:
 *   2011-5-25 14:45:37 Created by sky
 */
package com.jade.bss.base.customer;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.*;
import javax.validation.constraints.Pattern;

import com.jade.bss.base.BssConstants;
import com.jade.bss.base.utils.RegValidation;

/**
 * 客户对象。
 *
 * @author sky
 * @version 1.0 2012-5-25 14:45:37
 */
@Entity
@Table (name = "BSS_CUSTOMER")
public class Customer implements Serializable
{
    //客户默认类型
    public static final String ADMIN_TYPE = "admin";
    public static final String DEFAULT_TYPE = "default";
    public static final int SEX_FEMALE = 0;
    public static final int SEX_MALE = 1;
    /** 客户未激活 */
    public static int STATUS_INACTIVE = 0;
    /** 正常状态 */
    public static int STATUS_ACTIVE = 1;
    /** 客户被暂停 */
    public static int STATUS_SUSPEND = 5;
    /** 客户被临时删除，还可以恢复 */
    public static int STATUS_DELETED_TEMP = 8;
    /** 客户被彻底删除，等待回收 */
    public static int STATUS_DELETED = 9;
    /** 用户正常设置密码 */
    public static int PASSFLAG_USER = 0;
    /** 系统初始设置密码 */
    public static int PASSFLAG_INIT = 1;
    /** 管理员重置密码 */
    public static int PASSFLAG_RESET = 2;
    /** customer identifier */
    @Id
    @GeneratedValue(generator = "SEQ_BSS_CUSTOMER")
    @SequenceGenerator(name = "SEQ_BSS_CUSTOMER", sequenceName = "SEQ_BSS_CUSTOMER")
    protected long id;
    /** 客户类型 */
    @Column(nullable = false, length = 32)
    protected String type = DEFAULT_TYPE;
    /** 客户名称类型，例如手机号码、邮件地址、QQ号、微信账号、微博账号等等 */
    @Column (nullable = false, length = 32)
    protected String nameType = "name";
    /** customer name */
    @Column (nullable = false, length = 64)
    protected String name;
    /** customer password, should be encrypted */
    @Column (nullable = true, length = 64)
    protected String password;
    /** 密码标记，包括用户正常设置，管理员重置等等 */
    @Column (name = "pass_flag", nullable = true)
    protected int passFlag = PASSFLAG_INIT;
    /** customer status. */
    @Column (nullable = false)
    protected int status = STATUS_ACTIVE;
    /** 客户昵称 */
    @Column (name = "nick_name", length = 32)
    protected String nickName;
    /** 客户真实名称 */
    @Column (name = "true_name", length = 64)
    protected String trueName;
    /** mobile number */
    @Column (length = 20)
    @Pattern(regexp= RegValidation.PHONE, message=RegValidation.PHONE_MSG)
    protected String mobile;
    /** email address */
    @Column (length = 32)
    @Pattern(regexp= RegValidation.EMAIL, message=RegValidation.EMAIL_MSG)
    protected String email;
    /** gender */
    protected int gender = SEX_MALE;
    /** 用户所在地区 */
    @Column (length = 32)
    protected String region;
    /** 用户所在国家, 冗余 */
    @Column (length = 32)
    protected String country;
    /** 用户所在身份 */
    @Column (length = 32)
    protected String province;
    /** 用户所在城市 */
    @Column (length = 32)
    protected String city;
    /** 用户所在县 */
    @Column (length = 32)
    protected String county;
    /** logo */
    @Column (name = "logo", length = 512)
    protected String logo;
    /** 类型 */
    @Column (name = "create_type", length = 32)
    protected String createType;
    /** creation date */
    @Column (name = "creation_date", nullable = false)
    protected Date creationDate = new Date();
    /** 生日 */
    @Column (name = "birthday")
    protected Date birthday;
    @Transient
    protected Map<Class, CustomerInfo> infos;
    //客户所有者类型
    @Column (name = "owner_type", nullable = false, length = 32)
    private String ownerType = BssConstants.OWNER_TYPE_SYSTEM;
    //客户所有者标识
    @Column (name = "owner_id", nullable = false, length = 64)
    private String ownerId = BssConstants.OWNER_ID_SYSTEM;
    @Column (name = "parent_id")
    private long parentId = 0;
    /** 客户级别 */
    @Column (name = "customer_level")
    private int level = 0;
    /** 客户分类 */
    @Column (name = "category_id")
    private long categoryId;
    @Column(name="uuid")
    private String uid;
    @Column(name="push_id")
    private String pushId;
    @Column(name="qq")
    private String qq;
    @Column(name="shareCode")
    private String shareCode;
    @Column(name="user_self_01")
    private long userSelf01;
    @Column(name="user_self_02")
    private long userSelf02;
    @Column(name="user_self_03")
    private long userSelf03;
    @Column(name="user_self_04")
    private String userSelf04;
    @Column(name="user_self_05")
    private String userSelf05;
    @Column(name="user_self_06")
    private String userSelf06;
    @Column(name="user_self_07")
    private String userSelf07;
    @Column(name="user_self_08")
    private String userSelf08;
    @Column(name="user_self_09")
    private String userSelf09;
    @Column(name="user_self_10")
    private String userSelf10;
    //    @ElementCollection (fetch = FetchType.EAGER)
//    @CollectionTable (name = "BSS_CUSTOMER_TAG", joinColumns = @JoinColumn (name = "customer_id"))
//    @Column (name = "tag", length = 64)
    @OneToMany (cascade = {CascadeType.PERSIST, CascadeType.REMOVE,CascadeType.MERGE}, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn (name = "customer_id")
    private List<CustomerTag> tags;

    public Date getBirthday()
    {
        return birthday;
    }

    public void setBirthday(Date birthday)
    {
        this.birthday = birthday;
    }

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public long getParentId()
    {
        return parentId;
    }

    public void setParentId(long parentId)
    {
        this.parentId = parentId;
    }

    public String getNameType()
    {
        return nameType;
    }

    public void setNameType(String nameType)
    {
        this.nameType = nameType;
    }

    public String getNickName()
    {
        return nickName;
    }

    public void setNickName(String nickName)
    {
        this.nickName = nickName;
    }

    public int getGender()
    {
        return gender;
    }

    public void setGender(int gender)
    {
        this.gender = gender;
    }

    public String getLogo()
    {
        return logo;
    }

    public void setLogo(String logo)
    {
        this.logo = logo;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getTrueName()
    {
        return trueName;
    }

    public void setTrueName(String trueName)
    {
        this.trueName = trueName;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public int getPassFlag()
    {
        return passFlag;
    }

    public void setPassFlag(int passFlag)
    {
        this.passFlag = passFlag;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public long getCategoryId()
    {
        return categoryId;
    }

    public void setCategoryId(long categoryId)
    {
        this.categoryId = categoryId;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate(Date creationDate)
    {
        this.creationDate = creationDate;
    }

    public String getMobile()
    {
        return mobile;
    }

    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public int getLevel()
    {
        return level;
    }

    public void setLevel(int level)
    {
        this.level = level;
    }

    public String getRegion()
    {
        return region;
    }

    public void setRegion(String region)
    {
        this.region = region;
    }

    public String getCountry()
    {
        return country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public String getProvince()
    {
        return province;
    }

    public void setProvince(String province)
    {
        this.province = province;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCounty()
    {
        return county;
    }

    public void setCounty(String county)
    {
        this.county = county;
    }

    public String getCreateType()
    {
        return createType;
    }

    public void setCreateType(String createType)
    {
        this.createType = createType;
    }

    public String getOwnerId()
    {
        return ownerId;
    }

    public void setOwnerId(String ownerId)
    {
        this.ownerId = ownerId;
    }

    public String getOwnerType()
    {
        return ownerType;
    }

    public void setOwnerType(String ownerType)
    {
        this.ownerType = ownerType;
    }

    public List<CustomerTag> getTags()
    {
        return tags;
    }

    public void setTags(List<CustomerTag> tags)
    {
        this.tags = tags;
    }

    public Map<Class, CustomerInfo> getInfos()
    {
        return infos;
    }

    public void setInfos(Map<Class, CustomerInfo> infos)
    {
        this.infos = infos;
    }


    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getPushId() {
        return pushId;
    }

    public void setPushId(String pushId) {
        this.pushId = pushId;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getShareCode() {
        return shareCode;
    }

    public void setShareCode(String shareCode) {
        this.shareCode = shareCode;
    }

    public long getUserSelf01() {
        return userSelf01;
    }

    public void setUserSelf01(long userSelf01) {
        this.userSelf01 = userSelf01;
    }

    public long getUserSelf02() {
        return userSelf02;
    }

    public void setUserSelf02(long userSelf02) {
        this.userSelf02 = userSelf02;
    }

    public long getUserSelf03() {
        return userSelf03;
    }

    public void setUserSelf03(long userSelf03) {
        this.userSelf03 = userSelf03;
    }

    public String getUserSelf04() {
        return userSelf04;
    }

    public void setUserSelf04(String userSelf04) {
        this.userSelf04 = userSelf04;
    }

    public String getUserSelf05() {
        return userSelf05;
    }

    public void setUserSelf05(String userSelf05) {
        this.userSelf05 = userSelf05;
    }

    public String getUserSelf06() {
        return userSelf06;
    }

    public void setUserSelf06(String userSelf06) {
        this.userSelf06 = userSelf06;
    }

    public String getUserSelf07() {
        return userSelf07;
    }

    public void setUserSelf07(String userSelf07) {
        this.userSelf07 = userSelf07;
    }

    public String getUserSelf08() {
        return userSelf08;
    }

    public void setUserSelf08(String userSelf08) {
        this.userSelf08 = userSelf08;
    }

    public String getUserSelf09() {
        return userSelf09;
    }

    public void setUserSelf09(String userSelf09) {
        this.userSelf09 = userSelf09;
    }

    public String getUserSelf10() {
        return userSelf10;
    }

    public void setUserSelf10(String userSelf10) {
        this.userSelf10 = userSelf10;
    }

    public void addInfo(CustomerInfo info)
    {
        if (infos == null) {
            infos = new HashMap<Class, CustomerInfo>();
        }
        infos.put(info.getClass(), info);
    }

    @SuppressWarnings (value = "unchecked")
    public <T extends CustomerInfo> T getInfo(Class infoClass)
    {
        if (infos == null) {
            return null;
        }
        return (T) infos.get(infoClass);
    }
}
